<%@ page language="java" import="java.util.*"
	contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="com.model.Possession"%>
<%@ page import="com.control.PossessionControl"%>
<%@ page import="com.util.PageResultSet"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>查看寝室物品</title>
	</head>
	<body>
		<%
		    request.setCharacterEncoding("UTF-8");
		    int admin_id = (Integer)session.getAttribute("user_id");
		    String ToolBar = "";
		    int curPage = 1;
	    	ArrayList<Possession> list = new ArrayList<Possession>();
	    	PossessionControl pc = new PossessionControl();
	    	String res = "";
	    	String dorm = "";
	    	if(request.getParameter("res") != null){
	    		res = request.getParameter("res");
	    		session.setAttribute("res",res);
	    	}
	    	if(request.getParameter("dorm") != null){
	    		dorm = request.getParameter("dorm");
	    		session.setAttribute("dorm",dorm);
	    	}
	    	//System.out.println("res_name="+res);
	    	//System.out.println("dorm_name="+dorm);
	    	list = pc.getAdminPossession(admin_id, dorm, res);
	    	if(request.getParameter("cur_page")!= null) {
				curPage = Integer.parseInt(request.getParameter("cur_page")); 
			}
			PageResultSet p = new PageResultSet(list,curPage);
			ArrayList<Possession> nowlist = new ArrayList<Possession>();
			nowlist = (ArrayList<Possession>)p.getData();
		%>
		<table width="98%" border="0" align="center">
			<tr>
				<td></td>
			</tr>
			<tr>
				<td></td>
			</tr>
			<tr>
				<td>
					<fieldset>
						<legend>
							物品列表
						</legend>
						<form action="possession_show.jsp" name="form1" method="post">
							<table width="100%" border="0" cellspacing="0" cellpadding="0">
								<tr height="10">
									<td></td>
								</tr>
								<tr align="center">
									<td align="center">
								    <%
								       	if(session.getAttribute("dorm") != null) {
	    									dorm = (String)session.getAttribute("dorm");
	    								}
							        %>
								       	寝室名
								        <input name="dorm" type="text" id="dorm" size="5" value="<%=dorm %>"/>
								    <%
								       	if(session.getAttribute("res") != null) {
	    									res = (String)session.getAttribute("res");
	    								}
							        %>
								       	物品名
								        <input name="res" type="text" id="res size="5" value="<%=res %>"/>
										<input type="submit" value="查询" />
									</td>
								</tr>
							</table>
							<table width="50%" border="0" align="center" cellspacing="0"
								cellpadding="0">
								<tr>
									<td height="20"></td>
								</tr>
								<tr>
									<td>
										<table border="1" width="99%" align="center" cellpadding="0"
											cellspacing="1" class="resultTable">
											<tr>
												<td width="3%" height="25" align="center" bgcolor="#D9F0FF">
													寝室
												</td>
												<td width="4%" height="25" align="center" bgcolor="#D9F0FF">
													物品名
												</td>
												<td width="2%" height="25" align="center" bgcolor="#D9F0FF">
													数量
												</td>
												<td width="4%" height="25" align="center" bgcolor="#D9F0FF">
													操作
												</td>
								</tr>
								<%
										
										
										for(int i=0; i<nowlist.size(); i++) {
											Possession poss = nowlist.get(i);
									 %>
								 	<tr>
        								<td height="25" align="center"><%=poss.getDorm_name()%></td>
 										<td height="25" align="center"><%=poss.getRes_name()%></td>
 										<td height="25" align="center"><%=poss.getPoss_num()%></td>
 		 								<td height="25" align="center"><a href="possession_show.jsp?id=<%=poss.getPoss_id()%>">修改数量 </a></td>
 									</tr>
   									<%}
   										
										String fileName = "possession_show.jsp";
										ToolBar = p.getToolBar(fileName);
										//System.out.println(ToolBar);
									%>
							</table>
							<%=ToolBar %>
							
							</td>
							</tr>
							</table>
						</form>
					</fieldset>
				</td>
			</tr>
		</table>
		<%
			if(request.getParameter("id")!=null){
				int poss_id = Integer.parseInt(request.getParameter("id"));
		%>
				<script type="text/javascript">
    				var num=prompt("请输入数据:","");	
    		 		if(num!="" && num!=null)
						location="update_possession.jsp?poss_id=<%=poss_id%>&input_num="+num;
 				</script>
				
		<%}%>
	</body>
</html>
